/*
 * Copyright 2012 ilem, Inc. www.ilemgroup.com 
 * Geneva, Switzerland
 * All rights reserved.
 */
package ch.ilem.api.web.json;

import java.util.List;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;

import org.apache.commons.cli.*;

import flexjson.*;

import ch.ilem.common.dto.DtoGeneric;

// API
import ch.ilem.api.biz.*;


/**
 * Use java -Djava.util.logging.config.file=myfile
 * @author <a href="mailto:philippe.delobel@ilem.ch">Philippe Delobel</a>
 * @date 19.12.2010
 * @version $$Revision$$
 */
public class JsonTester {

	
    public static Logger logger = Logger.getLogger(JsonTester.class.getName());
    
    private static java.sql.Connection connexion = null;

    public static void main(String[] args) {
    
        Options options = new Options();
        
        @SuppressWarnings("static-access")
		Option help = OptionBuilder.withLongOpt("help").
        withDescription("help").
        create();

        @SuppressWarnings("static-access")
		Option maxrow = OptionBuilder.withLongOpt("maxrow").
        hasArg().
        isRequired().
        withDescription("Max rows to process").
        create();

        options.addOption(help);
        options.addOption(maxrow);
        
    	CommandLineParser parser = new PosixParser();
    	
    	try {
			CommandLine cmd = parser.parse(options, args);
			if (cmd.hasOption("help")) {
				HelpFormatter formatter = new HelpFormatter();
				formatter.printHelp( "run", options );				
			} else {
				logger.info("Args OK");
				logger.info("--> maxrow=[" + cmd.getOptionValue("maxrow") + "]");
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			logger.severe("Args");
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp( "run", options );
		}
		
		// Get the implementation
		try {
			
			// call data selector service
			// DataSelectorApi ds = DataSelectorFactory.getInstance(DataSelectorImplMock.class);
			// List<DtoGeneric> invoices = ds.selectByCriteria(null);

			JSONSerializer serializer = new JSONSerializer();
			logger.info("JSON RESULT -->");
			// logger.info(serializer.serialize(invoices));
			logger.info("JSON RESULT <--");
			
		} catch (Exception e) {
			logger.severe("ERROR=" + e.getMessage());
			e.printStackTrace();
		} 
		finally {
		}

		logger.info("Ending");
    	
    }   
    
}
